FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN sed -i 's|http://archive.ubuntu.com|http://mirrors.aliyun.com|g' /etc/apt/sources.list && \
  apt-get update && \
    apt-get install -y \
    xfce4 xfce4-goodies \
    tigervnc-standalone-server tigervnc-common \
    wget curl git sudo vim iproute2 \
    supervisor \
    fonts-wqy-zenhei fonts-wqy-microhei fonts-liberation \
    fcitx5 fcitx5-chinese-addons fcitx5-frontend-gtk2

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone 

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
  dpkg -i google-chrome-stable_current_amd64.deb && \
  rm /*.deb && \
  apt-get clean && rm -rf /var/lib/apt/lists/*

RUN apt-get purge -y xfce4-power-manager-plugins xfce4-screensaver \
  xfce4-battery-plugin xfce4-dict xfce4-mailwatch-plugin xfce4-smartbookmark-plugin xfce4-wavelan-plugin xfce4-weather-plugin \
  man-db yelp yelp-xsl xorg-docs-core \
  wpasupplicant eject \
  gnome-terminal nautilus-extension-gnome-terminal \
  ristretto xfburn thunar-media-tags-plugin thunar-archive-plugin \
  modemmanager usb-modeswitch usb-modeswitch-data && \
  apt autoremove -y && \
  rm -f /etc/xdg/autostart/light-locker.desktop

ARG USERNAME=ubuntu
ARG PASSWORD=ubuntu

RUN sed -i '/plugin-.*notification.*/d' \
    /etc/xdg/xfce4/panel/default.xml \
    /home/$USERNAME/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml \
    || true

RUN useradd -m -s /bin/bash -u 1000 $USERNAME && \
    echo "$USERNAME:$PASSWORD" | chpasswd && \
    usermod -aG sudo $USERNAME

# google chrome
COPY *.desktop /home/$USERNAME/Desktop/

RUN chmod +x /home/$USERNAME/Desktop/*.desktop && \
    chown -R $USERNAME:$USERNAME /home/$USERNAME/Desktop/

# input method
COPY fcitx5_profile  /home/$USERNAME/.config/fcitx5/profile
RUN chown -R $USERNAME:$USERNAME /home/$USERNAME/.config/ && \
    chmod 600 /home/$USERNAME/.config/fcitx5/profile

COPY entrypoint.sh /entrypoint.sh
RUN  chmod +x /entrypoint.sh && \
  chown -R $USERNAME:$USERNAME /entrypoint.sh

USER $USERNAME
WORKDIR /home/$USERNAME

ARG VNC_PW=ubuntu
ENV VNC_PW=${VNC_PW}

COPY supervisord.conf /supervisord.conf

ENV DISPLAY=:1

EXPOSE 5901

CMD ["/entrypoint.sh"]

